package com.edu.exam.enums.core;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 教室状态枚举
 */
public enum RoomStatus implements BaseEnum {
    ACTIVE("ACTIVE", "启用"),
    INACTIVE("INACTIVE", "停用"),
    UNDER_MAINTENANCE("UNDER_MAINTENANCE", "维护中"),
    RENOVATION("RENOVATION", "装修中"),
    TEMPORARILY_CLOSED("TEMPORARILY_CLOSED", "暂时关闭"),
    PERMANENTLY_CLOSED("PERMANENTLY_CLOSED", "永久关闭"),
    RESERVED("RESERVED", "预留"),
    DAMAGED("DAMAGED", "损坏");

    private final String code;
    private final String description;

    RoomStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static RoomStatus fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Room status code cannot be null or empty");
        }

        for (RoomStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown RoomStatus code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static RoomStatus fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("Room status description cannot be null or empty");
        }

        for (RoomStatus status : values()) {
            if (status.getDescription().equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown RoomStatus description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}